package com.spring.lesson001.demo6;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author vhans
 */
public class DiAutowireTest {

    @Test
    public void diAutowireByName() {
        String beanXml = "diAutowireByName0016.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println(context.getBean("diAutowireByName1"));
        System.out.println("------------");
        System.out.println(context.getBean("diAutowireByName2"));
    }

    @Test
    public void diAutowireByType() {
        String beanXml = "diAutowireByType0016.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println(context.getBean("diAutowireByType"));
    }

    @Test
    public void diAutowireByTypeExtend() {
        String beanXml = "diAutowireByTypeExtend0016.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        DiAutowireByTypeExtend diAutowireByTypeExtend = context.getBean(DiAutowireByTypeExtend.class);
        System.out.println("serviceList" + diAutowireByTypeExtend.getServiceList());
        System.out.println("baseServiceList" + diAutowireByTypeExtend.getBaseServiceList());
        System.out.println("serviceMap" + diAutowireByTypeExtend.getServiceMap());
        System.out.println("baseServiceMap" + diAutowireByTypeExtend.getBaseServiceList());
    }

    @Test
    public void diAutowireByConstructor() {
        String beanXml = "diAutowireByConstructor0016.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println(context.getBean("diAutowireByConstructor"));
    }

    @Test
    public void diAutowireByDefault() {
        String beanXml = "diAutowireByDefault0016.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println(context.getBean("diAutowireByDefault1"));
        System.out.println(context.getBean("diAutowireByDefault2"));
    }
}
